/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.controller.interfaces.AbstractController;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Lucas
 *
 */
public class UnitController extends AbstractController<Unit> {
	
	DaoFactory daoFactory;
	
	public UnitController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Unit());
	}
	
	public void changeName(String name) {
		getModel().setName(name);
	}
	
	public void persistDelete(Unit unit) {
		daoFactory.beginTransaction();
		daoFactory.createUnitDao().delete(unit);
		daoFactory.commitTransaction();
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createUnitDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createUnitDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public List<Unit> persistSearchByExample(Unit example) {
		daoFactory.beginTransaction();
		List<Unit> unitList = daoFactory.createUnitDao().searchByExample(example);
		daoFactory.commitTransaction();
		return unitList;
	}

}
